package com.itheima.datastructure;


import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.function.Consumer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;

public class TestDynamicArray {
    DynamicArray dynamicArray = new DynamicArray();

    @BeforeEach
    public void before() {
        for (int i = 0; i < 9; i++) {
            dynamicArray.addLast(i + 1);
        }
    }


    @Test
    public void test_01() {
        dynamicArray.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });
    }

    @Test
    public void test_03() {

        for (Integer element : dynamicArray) {  //hasNext() next()
            System.out.println(element);
        }
    }

    @Test
    public void test4() {
        dynamicArray.stream().forEach(element -> {
            System.out.println(element);
        });
    }

    @Test
    public void test5() {
        int removed = dynamicArray.remove(2);
        assertEquals(3, removed);
        assertIterableEquals(List.of(1, 2, 4), dynamicArray);
    }

    @Test
    public void test6() {
        assertIterableEquals(List.of(1,2,3,4,5,6,7,8,9), dynamicArray);
    }
}
